package com.vertx.starter;

import com.google.inject.Inject;
import io.vertx.core.Vertx;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class RestRouterImpl implements RestRouter {

    @Inject
    private UserRouter userRouter;

    @Override
    public Router create(Vertx vertx) {
        Router router = Router.router(vertx);
        router.route().consumes("application/json; charset=utf-8");
        router.route().produces("application/json; charset=utf-8");
        router.route()
                .handler(BodyHandler.create())
                .handler(ctx -> {
                    log.info("请求路径：{}", ctx.request().absoluteURI());
                    ctx.next(); // 可执行多个handler
                });
        router.mountSubRouter("/user", userRouter.create(vertx));
        log.info("初始化路由完成！");
        return router;
    }

}
